package com.lanchetech.merchant.controller;

import com.lanchetech.bean.request.CategoryReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.CategoryInfoResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.CategoryEditVO;
import com.lanchetech.bean.vo.ShopCategoryEditVO;
import com.lanchetech.entity.Category;
import com.lanchetech.entity.ShopCategory;
import com.lanchetech.merchant.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "类目接口", tags = "类目接口")
@RequestMapping("/api/category")
@RestController
public class CategoryController {

    @Autowired
    CategoryService categoryService;


    @ApiOperation("获取一级二级类目列表")
    @GetMapping("/getTwoLevelCategoryList")
    public ResultData<List<Category>> getTwoLevelCategoryList(@RequestParam("type") Byte type) {
        return categoryService.getTwoLevelCategoryList(type);
    }

    @ApiOperation("获取根类目列表")
    @GetMapping("/getRootCategoryList")
    public ResultData<List<Category>> getRootCategoryList(@RequestParam("type") Byte type) {
        return categoryService.getRootCategoryList(type);
    }

    @ApiOperation("获取所有类目列表")
    @GetMapping("/getAllCategoryList")
    public ResultData<List<Category>> getAllCategoryList(@RequestParam("type") Byte type) {
        return categoryService.getAllCategoryList(type);
    }

    @ApiOperation("获取子类目列表")
    @GetMapping("/getChildrenCategory")
    public ResultData<List<Category>> getChildrenCategory(@RequestParam("id") Long id) {
        return categoryService.getChildrenCategory(id);
    }

    @ApiOperation("获取类目详情")
    @GetMapping("/getCategoryDetail")
    public ResultData<CategoryEditVO> getCategoryDetail(@RequestParam("id") Long id) {
        return categoryService.getCategoryDetail(id);
    }

    @ApiOperation("获取类目品牌、销售属性、自然属性")
    @GetMapping("/getCategoryInfo")
    public ResultData<CategoryInfoResp> getCategoryInfo(@RequestParam("id") Long id) {
        return categoryService.getCategoryInfo(id);
    }

    @ApiOperation("获取所有商家类目列表")
    @GetMapping("/getAllShopCategoryList")
    public ResultData<List<ShopCategory>> getAllShopCategoryList() {
        return categoryService.getAllShopCategoryList();
    }

    @ApiOperation("添加或编辑商家类目")
    @PostMapping("/editShopCategory")
    public BaseResp editShopCategory(@RequestBody ShopCategoryEditVO shopCategoryEditVO) {
        return categoryService.editShopCategory(shopCategoryEditVO);
    }

    @ApiOperation("删除商家类目")
    @GetMapping("/deleteShopCategory")
    public BaseResp deleteShopCategory(@RequestParam("id") Long id) {
        return categoryService.deleteShopCategory(id);
    }

    @ApiOperation("获取商家类目详情")
    @GetMapping("/getShopCategoryDetail")
    public ResultData<ShopCategory> getShopCategoryDetail(@RequestParam("id") Long id) {
        return categoryService.getShopCategoryDetail(id);
    }

    @ApiOperation("获取类目分页")
    @PostMapping("/getCategoryPage")
    public ResultData<BasePageResp<Category>> getCategoryPage(@RequestBody CategoryReq req) {
        return categoryService.getCategoryPage(req);
    }
}
